package com.ypj.servlet;

import com.ypj.domain.User;
import com.ypj.service.UserService;
import com.ypj.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userCode=request.getParameter("userCode");
        String userPassword=request.getParameter("userPassword");
        UserService userService=new UserServiceImpl();
        User user=userService.login(userCode,userPassword);
        if (user!=null){
            request.getSession().setAttribute("user",user);
            response.sendRedirect("jsp/frame.jsp");
        }else{
            request.setAttribute("error","用户名或密码不正确");
            request.getRequestDispatcher("login.jsp").forward(request,response);
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
